<template>
	<view class="flowDone-v">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :sticky="true"
			:down="downOption" :up="upOption">
			<view class="search-box search-box_sticky">
				<u-search placeholder="请输入关键词搜索" v-model="keyword" height="72" :show-action="false" @change="search"
					bg-color="#f0f2f6" shape="square">
				</u-search>
			</view>

			<view>
				<view style="padding: 15rpx 15rpx 0 15rpx;" v-for="(item, index) in dataForm" :key="item.id"
					@click="toDetail(item)">
					<view style="background-color: #fff;border-radius: 20rpx;padding:15rpx">
						<view class="title u-font-28 u-line-1" style="display: flex;justify-content: space-between;">
							<view> {{item.fullName}}</view>
							<view>
								<u-tag type="primary" v-if="item.status == 1" text="等待审核" />
								<u-tag type="success" v-else-if="item.status == 2" text="审核通过" />
								<u-tag type="error" v-else-if="item.status == 3" text="审核驳回" />
								<u-tag type="info" v-else-if="item.status == 4" text="流程撤回" />
								<u-tag type="info" v-else-if="item.status == 5" />
								<u-tag v-else type="warning" text="等待提交" />
							</view>
						</view>
						<view class="title u-line-1 u-font-24">
							发起时间:<text class="titInner">{{ timestampToDateTime(item.startTime)}} </text>
						</view>
						<view class="title u-line-1 u-font-24">
							发起人员:<text class="titInner">{{item.userName}}</text>
						</view>
						<view class="title u-line-1 u-font-24">
							审批节点:<text class="titInner">{{item.thisStep}}</text>
						</view>
						<view class="title u-line-1 u-font-24">
							紧急程度:<text class="titInner">{{item.flowUrgent}}</text>
						</view>
						<view class="title u-line-1 u-font-24" style="display: flex;">
							流程进度:
							<view style=" width: 100%;margin-left: 10rpx;">
								<u-line-progress active-color="#2979ff" :percent="item.completion"></u-line-progress>
							</view>
						</view>
					</view>

				</view>
			</view>
		</mescroll-body>
	</view>
</template>
<script>
	import resources from '@/libs/resources.js'
	import FlowBox from '@/pages/workFlow/flowBefore/flowForm.vue'
	import {
		getFlowMonitor
	} from '@/api/workFlow/flowBefore'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],

		data() {
			return {
				formVisible: false,
				keyword: '',
				dataForm: [],
				downOption: {
					use: true,
					auto: true
				},
				upOption: {
					page: {
						num: 0,
						size: 20,
						time: null
					},
					empty: {
						use: true,
						icon: resources.message.nodata,
						tip: "暂无数据",
						fixed: true,
						top: "300rpx",
					},
					textNoMore: '没有更多数据',
				},
			}
		},
		onLoad() {},
		onUnload() {},
		methods: {
			timestampToDateTime(timestamp) {
				return this.$utilsFun.timestampToDateTime(timestamp);
			},
			toDetail(item) {
				const config = {
					id: item.processId,
					enCode: item.flowCode,
					flowId: item.flowId,
					formType: item.formType,
					opType: 4,
					status: item.status,
					taskNodeId: item.thisStepId,
					fullName: item.fullName,
					taskId: item.id,
				}
				uni.setStorageSync('complexObject', JSON.stringify(config));
				uni.navigateTo({
					url: '/pages/workFlow/flowBefore/index'
				})
				// uni.navigateTo({
				// 	url: '/pages/workFlow/flowBefore/index?config=' + JSON.stringify(config)
				// })
				// console.log("点击传过去的参数config", config);
				// uni.navigateTo({
				// 	url: "/pages/workFlow/flowBefore/index",
				// 	success: (res) => {
				// 		console.log("res===》", res);
				// 		// 通过 eventChannel 向被打开页面传送数据
				// 		res.eventChannel.emit("acceptDataFromOpener", {
				// 			config: config
				// 		});
				// 	},
				// });
			},
			upCallback(page) {
				let query = {
					currentPage: page.num,
					pageSize: page.size,
					keyword: this.keyword
				}
				getFlowMonitor(query).then(res => {
					console.log('res', res);
					this.mescroll.endSuccess(res.data.list.length);
					if (page.num == 1) this.dataForm = [];
					let flowStatus;
					const list = res.data.list.map(o => (
						flowStatus = o.status == 1 ? resources.status.adopt : resources.status
						.refuse, {
							flowStatus: flowStatus,
							...o
						}));
					this.dataForm = this.dataForm.concat(list);
				}).catch(() => {
					this.mescroll.endErr();
				})
			},
			search() {
				// 节流,避免输入过快多次请求
				this.searchTimer && clearTimeout(this.searchTimer)
				this.searchTimer = setTimeout(() => {
					this.dataForm = [];
					this.mescroll.resetUpScroll();
				}, 300)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f0f2f6;
	}
</style>